package com.zyx.wanshu.config;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * @author zyx
 * @since 2022/7/15 22:14
 */
public class MyFastGeneratorConfiguration {
    public static String url = "jdbc:mysql://81.68.117.201:3306/db_test?allowPublicKeyRetrieval=true&" +
            "serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&" +
            "useSSL=true&nullCatalogMeansCurrent=true";
    public static String user = "test";
    public static String pwd = "test";
    public static String[] includeTables = {"sys_user", "sys_role",
            "sys_user_role", "sys_menu", "sys_role_menu", "sys_oplog"};
    public static final String tablePrefix = "sys_";

    public static void main(String[] args) {

        FastAutoGenerator.create(url, user, pwd)
                .globalConfig(builder -> {
                    builder.author("wanshu") // 设置作者
                            //.enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("D://wanshu"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.wanshu") // 设置父包名
                            .moduleName("wanshu") // 设置父包模块名
                            // 设置mapperXml生成路径
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "D://wanshu"));
                })
                .strategyConfig(builder -> {
                    builder.addInclude(includeTables) // 设置需要生成的表名
                            .addTablePrefix(tablePrefix); // 设置过滤表前缀

                })
                // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
